;
(function(){
	TempoMineDateConvertUtils = {};
	
	TempoMineDateConvertUtils.showTip = function(_msg) {
		$("<div/>").alert({
			msg : _msg,
			title : TempoUtils.locale("core.prompt")
		});
	}
	
	TempoMineDateConvertUtils.getDateformatLabels = function() {
		return ["20010315", "2001-03-15", TempoUtils.locale("mine.ymd"), TempoUtils.locale("mine.ym"), TempoUtils.locale("mine.md"),TempoUtils.locale("mine.cymd"), TempoUtils.locale("mine.cmd"), "2001/03/15 09:20:30", "2001/03/15", "03/14", "2001-01-01T12:00:03.000Z","2001-03-15 09:20:30","2001/03/15 09:20:30.123","2001-03-15 09:20:30.123","zdy"];
	}
	TempoMineDateConvertUtils.getDateformatLabelsNoMillsecond = function() {
		return ["20010315", "2001-03-15", TempoUtils.locale("mine.ymd"), TempoUtils.locale("mine.ym"), TempoUtils.locale("mine.md"),TempoUtils.locale("mine.cymd"), TempoUtils.locale("mine.cmd"), "2001/03/15 09:20:30", "2001/03/15", "03/14", "2001-01-01T12:00:03.000Z","2001-03-15 09:20:30","zdy"];
	}
	
	TempoMineDateConvertUtils.getDateRadioHtml = function(idx, labelName) {
		var html = "<td class='formLayoutTit'>"; 
		html += "<input name='tempo-mine-dateType-radio' id='radio_" + idx +"' type='radio' ui-role='radio' >";
		html += "<label for='radio_" + idx +"'>" + labelName + "</label></td>";
		return html;
	}
	 
	TempoMineDateConvertUtils.getDateConvertTableHtml = function(isNotShowMillsecond) {
		var tableHtml = "<legend style='padding-bottom: 10px; padding-left: 15px;font-size: larger;'>"
			+ TempoUtils.locale("mine.predataformat")
			+ "</legend><div class='tempo-columnselect-datetype'><table width='100%' height='100%' class='tempo-date-convert-formLayout'>";
		var dateformatLabels = TempoMineDateConvertUtils.getDateformatLabels();
		if(isNotShowMillsecond){
			dateformatLabels =TempoMineDateConvertUtils.getDateformatLabelsNoMillsecond();
		}
		for (var idx = 0; idx < dateformatLabels.length - 1; idx++) {
			//id==12被自定义用了，为了兼容历史>=12的话，ids+1
			if(idx>=12){
				idx=idx+1;
				tableHtml += TempoMineDateConvertUtils.getDateRadioHtml(idx, dateformatLabels[idx-1]);
				idx++;
				if(idx < dateformatLabels.length){
					tableHtml += TempoMineDateConvertUtils.getDateRadioHtml(idx, dateformatLabels[idx-1]);
				}
			}else{
				tableHtml += TempoMineDateConvertUtils.getDateRadioHtml(idx, dateformatLabels[idx]);
				idx++;
				if(idx < dateformatLabels.length - 1){
					tableHtml += TempoMineDateConvertUtils.getDateRadioHtml(idx, dateformatLabels[idx]);
				}
			}

			tableHtml += "</tr>";
		}
		tableHtml += "</table></div>";
		return tableHtml;
	}
	
	TempoMineDateConvertUtils.getDateConvertCustomHtml = function() {
		var customHtml = "<div class='tempo-customDatetype'><table width='100%' height='100%'  class='tempo-date-convert-formLayout'>";
		customHtml += "<tr><td class='formLayoutTit'><input name='tempo-mine-dateType-radio' id='radio_12' type='radio' ui-role='radio' ><label for='radio_12' style='font-size: larger;'>"+TempoUtils.locale("mine.customize")+"</label>";
		customHtml += "<input id='text' ui-role='text' name='numClusters' style='width: 250px;' placeholder='yyyy/MM/dd HH:mm:ss" + TempoUtils.locale("mine.inputtip")+"'/></td></tr></div>";
		return customHtml;
	}
	
	TempoMineDateConvertUtils.getDateConvertHelpHtml = function() {
		var helpInfoHtml ="<div id='helpIno' style='background: rgb(243, 245, 247);position:absolute;position:absolute;width:350px;height:180px;backgroud:#e0e5e5;box-shadow:0px 0px 10px rgb(46, 49, 53);z-index:99999;'><table id='infoTable' class='tempo-date-convert-formLayout'><tr><td class='formLayoutTit'>"
			+ TempoUtils.locale("mine.formathelpinfo") + "</td></tr><tr><td class='formLayoutTit'>" + TempoUtils.locale("mine.formathelpinfo2") + "</td></tr><tr><td class='formLayoutTit'>" + TempoUtils.locale("mine.example") 
			+ "1：<br>yyyy?MM?dd</td></tr><tr><td class='formLayoutTit'>" + TempoUtils.locale("mine.example") + "2：<br>yyyy-MM-dd HH:mm:ss</td></tr><tr><td class='formLayoutTit'>" + TempoUtils.locale("mine.example") + "3：<br>yyyy-MM-dd HH:mm:ss.SSS</td></tr></table></div>";
		return helpInfoHtml;
	}

	TempoMineDateConvertUtils.initDateConvertDialog = function (parentElem, parameters, selectedIds, rowId, isDefault, isNotShowMillsecond) {
		$(".tempo-mine-date-convert-dialog").remove();
		var dateConvertDialog = $("<div/>").addClass("tempo-mine-date-convert-dialog").appendTo($('body')).dialog({
			width: 500,
			height: 420,
			modal: true,
			title: TempoUtils.locale("mine.oformatsetting"),
			resizable: false,
			close: function () {
				$(this).dialog("destroy").remove();
			},
			dragStop: function () {
				var x = $("#disinfo").offset().left;
				var y = $("#disinfo").offset().top;
				if (window.screen.width == 1366) {
					y = y - 225;
				}
				$("#helpIno").css("left", x + 20);
				$("#helpIno").css("top", y + 20);
			},
			open: function () {
				var tableHtml = TempoMineDateConvertUtils.getDateConvertTableHtml(isNotShowMillsecond);
				$(this).append(tableHtml);
				var customHtml = TempoMineDateConvertUtils.getDateConvertCustomHtml();
				$(this).append(customHtml);
				var helpInfoHtml = TempoMineDateConvertUtils.getDateConvertHelpHtml();
				//修改56077bug
				$(this).find(".formLayoutTit").css("height", "19px");
				//判断只初始化一次
				if ($("#helpIno").length == 0) {
					$('body').append(helpInfoHtml);
				}
				var disinfo = $(".tempo-customDatetype>table>tbody>tr>td").append("<span class='ui-icon tempo-ui-icon tempo-ui-icon-tip tempo-mine-button' id='disinfo'></span>");
				var x = $("#disinfo").offset().left;
				var y = $("#disinfo").offset().top;
				if (window.screen.width == 1366) {
					y = y - 225;
				}
				$("#helpIno").css("left", x + 20);
				$("#helpIno").css("top", y + 10);
				$("#helpIno").css("height", 225);
				$("#helpIno").hide();
				$("#disinfo").mouseover(function () {
					$("#helpIno").show();
				});
				$("#disinfo").mouseout(function () {
					$("#helpIno").hide();
				});
				if (selectedIds[rowId] != null) {
					if (selectedIds[rowId].indexOf("radio_") != -1) {
						$(this).find("input#" + selectedIds[rowId]).prop("checked", true);
					} else {
						$(this).find("input#radio_12").prop("checked", true);
						$(this).find("input#radio_12").parent().find("input#text").val(selectedIds[rowId]);
					}
				} else {
					if (isDefault) {
						$(this).find("input#radio_11").prop("checked", true);
					}
				}
			},
			buttons: [{
				text: TempoUtils.locale("mine.publish-dialog-sure"),
				click: function () {
					selectedIds[rowId] = $(this).find("input[type='radio']:checked").attr("id");
					if (selectedIds[rowId] == "radio_12") {
						selectedIds[rowId] = $(this).find("input[id='text']").val();
					}
					parameters.selectedId = selectedIds;
					if (selectedIds[rowId] == null || selectedIds[rowId] == "") {
						TempoMineDateConvertUtils.showTip(TempoUtils.locale("mine.nodataType"));
						return;
					}
					$(this).dialog('close');
				}
			},
				{
					text: TempoUtils.locale("mine.publish-dialog-cancel"),
					click: function () {
						$(this).dialog('close');
					}
				}]
		});
	}

	/**
	 * 增加原格式设置的弹出框，只有原格式设置(单独设置)
	 * @param parentElem
	 * @param parameters
	 * @param selectedIds
	 * @param rowId
	 * @param isDefault
	 */
	TempoMineDateConvertUtils.initDateConvertOnlyCustomDialog = function(parentElem, parameters, selectedIds, rowId, isDefault) {
		$(".tempo-mine-date-convert-dialog").remove();
		var dateConvertDialog = $("<div/>").addClass("tempo-mine-date-convert-dialog").appendTo($('body')).dialog({
			width:400,
			height:200,
			modal:true,
			title:TempoUtils.locale("mine.oformatsetting"),
			resizable:false,
			close:function(){
				$(this).dialog("destroy").remove();
			},
			dragStop:function(){
				var x = $("#disinfo").offset().left;
				var y = $("#disinfo").offset().top;
				$("#helpIno").css("left", x+20);
				$("#helpIno").css("top", y+20);
			},
			open:function() {
				debugger
				var tableHtml = "<legend style='font-size: larger;'>" + TempoUtils.locale("mine.predataformat") + "（选填）" + "</legend>";
				//var tableHtml = TempoMineDateConvertUtils.getDateConvertTableHtml();
				$(this).append(tableHtml);
				var customHtml = TempoMineDateConvertUtils.getDateConvertCustomHtml();
				$(this).append(customHtml);
				//为了兼容历史，只能把之前的各种日期类型隐藏掉，不能删除
				$(this).find("#radio_12").hide();
				$(this).find("#text").css("margin-left","5px");
				var helpInfoHtml = TempoMineDateConvertUtils.getDateConvertHelpHtml();
				//判断只初始化一次
				if($("#helpIno").length == 0){
					$('body').append(helpInfoHtml);
				}
				var disinfo = $(".tempo-customDatetype>table>tbody>tr>td").append("<span class='ui-icon tempo-ui-icon tempo-ui-icon-tip tempo-mine-button' id='disinfo'></span>");
				var x = $("#disinfo").offset().left;
				var y = $("#disinfo").offset().top;
				$("#helpIno").css("left", x+20);
				$("#helpIno").css("top", y+10);
				$("#helpIno").css("height", 224);
				$("#helpIno").hide();
				$("#disinfo").mouseover(function(){
					$("#helpIno").show();
				});
				$("#disinfo").mouseout(function(){
					$("#helpIno").hide();
				});
				$(this).find("input#radio_12").prop("checked",true);
				if (selectedIds[rowId] != null) {
					if (selectedIds[rowId].indexOf("radio_") != -1) {
					} else {
						$(this).find("input#radio_12").parent().find("input#text").val(selectedIds[rowId]);
					}
				}
			},
			buttons : [{
				text : TempoUtils.locale("mine.publish-dialog-sure"),
				click : function() {
					selectedIds[rowId] = $(this).find("input[type='radio']:checked").attr("id");
					if(selectedIds[rowId] == "radio_12"){
						selectedIds[rowId] = $(this).find("input[id='text']").val();
					}
					parameters.selectedId = selectedIds;
					/*if (selectedIds[rowId] == null || selectedIds[rowId] == ""){
						TempoMineDateConvertUtils.showTip(TempoUtils.locale("mine.nodataType"));
						return;
					}*/
					$(this).dialog('close');
				}
			},
				{
					text : TempoUtils.locale("mine.publish-dialog-cancel"),
					click : function() {
						$(this).dialog('close');
					}
				}]
		});
	}

	/**
	 * 增加原格式设置的弹出框，只有原格式设置(批量设置)
	 * @param parameters 参数值
	 */
	TempoMineDateConvertUtils.initBatchDateConvertOnlyCustomDialog = function(parameters) {
		$(".tempo-mine-date-convert-dialog").remove();
		var dateConvertDialog = $("<div/>").addClass("tempo-mine-date-convert-dialog").appendTo($('body')).dialog({
			width:400,
			height:200,
			modal:true,
			title:TempoUtils.locale("mine.oformatsetting"),
			resizable:false,
			close:function(){
				$(this).dialog("destroy").remove();
			},
			dragStop:function(){
				var x = $("#disinfo").offset().left;
				var y = $("#disinfo").offset().top;
				$("#helpIno").css("left", x+20);
				$("#helpIno").css("top", y+20);
			},
			open:function() {
				debugger
				var tableHtml = "<legend style='font-size: larger;'>" + TempoUtils.locale("mine.predataformat") + "（选填）" + "</legend>";
				$(this).append(tableHtml);
				var customHtml = "<div class='tempo-customDatetype'><table width='100%' height='100%'  class='tempo-date-convert-formLayout'>";
				customHtml += "<tr><td class='formLayoutTit'><label for='radio_12' style='font-size: larger;'>"+TempoUtils.locale("mine.customize")+"</label>";
				customHtml += "<input id='text' ui-role='text' name='numClusters' style='width: 250px;' placeholder='yyyy/MM/dd HH:mm:ss" + TempoUtils.locale("mine.inputtip")+"'/></td></tr></div>";
				$(this).append(customHtml);
				$(this).find("#text").css("margin-left","5px");
				var helpInfoHtml = TempoMineDateConvertUtils.getDateConvertHelpHtml();
				//判断只初始化一次
				if($("#helpIno").length == 0){
					$('body').append(helpInfoHtml);
				}
				var disinfo = $(".tempo-customDatetype>table>tbody>tr>td").append("<span class='ui-icon tempo-ui-icon tempo-ui-icon-tip tempo-mine-button' id='disinfo'></span>");
				var x = $("#disinfo").offset().left;
				var y = $("#disinfo").offset().top;
				$("#helpIno").css("left", x+20);
				$("#helpIno").css("top", y+10);
				$("#helpIno").css("height", 220);
				$("#helpIno").hide();
				$("#disinfo").mouseover(function(){
					$("#helpIno").show();
				});
				$("#disinfo").mouseout(function(){
					$("#helpIno").hide();
				});
			},
			buttons : [{
				text : TempoUtils.locale("mine.publish-dialog-sure"),
				click : function() {
					debugger
					//临时存储批量原格式值
					parameters.batchDateConvertValue = $(this).find("input[id='text']").val();
					$(this).dialog('close');
				}
			},
				{
					text : TempoUtils.locale("mine.publish-dialog-cancel"),
					click : function() {
						$(this).dialog('close');
					}
				}]
		});
	}
})(jQuery);